package com.study.ssm.aware;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * <pre>
 *     project name: SpringStudy
 *     author      : 李琼
 *     e-mail      : 1265137718@qq.com
 *     create time : 2017/9/15 上午1:49
 *     desc        : 描述--//MoocApplicationContext TODO
 *     URL         : CSDN:http://blog.csdn.net/qq_22945151
 *                   GitHub:https://github.com/a1265137718
 *     Reference   ://
 *     modifier               :
 *     modification time      :
 *     modify remarks         :
 *
 *     @version: --//TODO
 * </pre>
 */


public class MyApplicationContext implements ApplicationContextAware{
    ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        //在这里获取到ApplicationContext对象,这个接口的意义在于可以通过该接口获取到ApplicationContext,通过该接口
        //可以初始化
        this.applicationContext = applicationContext;
        MyApplicationContext myApplicationContext = (MyApplicationContext) applicationContext.getBean("myApplicationContext");
        System.out.println("MyApplicationContext.setApplicationContext"+
                myApplicationContext.hashCode());
    }

    public void initBeanInMySpringContext(){
        if (applicationContext.containsBean("testOutputBean")) {
            TestOutputBean testOutputBean = (TestOutputBean) applicationContext.getBean("testOutputBean");
            testOutputBean.say();
        }else {
            System.out.println("该类不存在于配置文件中");
        }

    }

}
